//@flow
import React from 'react'
import {
  createStore,
  applyMiddleware,
  compose,
 } from 'redux'
import { Provider } from 'react-redux'
import {
  GraphUri,
} from './config'
import reducers from './reducers'
import AppRouter from './router'
import { ApolloProvider } from 'react-apollo'
import ApolloClient from 'apollo-client'
import createNetworkInterface from './util/networkInterface'

const networkInterface = createNetworkInterface({
  uri:GraphUri,
  getToken(){
    return "123"
  },
})
const client = new ApolloClient({
  networkInterface,
})
global.apolloClient = client

const store = createStore(reducers(apolloClient.reducer()),
  {},
  compose(applyMiddleware(client.middleware()))
)
global.store = store


const App = React.createClass({
  componentWillMount(){
  },
  render(){
    return (
      <ApolloProvider store={store} client={client}>
        <AppRouter store={store}/>
      </ApolloProvider>
    )
  },
})

function initApp(){

  return () => <App/>
}

export default initApp
